//
//  ICMRepairMaintenanceModel.m
//  ICrEAM
//
//  Created by FoREVer_SaD on 16/10/28.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "ICMRepairMaintenanceModel.h"
#import "ICMMaintenanceAndPartsView.h"
#import "ICMAppointmentMaintenanceAndPartsView.h"

@implementation ICMRepairMaintenanceModel

-(BOOL)isDiscount{
    if ([self.IS_DISCOUNT isEqualToString:@"12781001"]) {
        return NO;
    }else{
        return YES;
    }
}

- (void)setLABOUR_PRICE:(NSString *)LABOUR_PRICE{
    _LABOUR_PRICE = LABOUR_PRICE;
    long price = [LABOUR_PRICE doubleValue]*100;
    long quantity = [_STD_LABOUR_HOUR doubleValue]*100;
    double totalPrice = price*quantity/10000.0;
    if(price != 0 && quantity != 0)
    {
        self.LABOUR_AMOUNT = [NSString stringWithFormat:@"%.2lf", totalPrice];
    }
}


- (void)setSTD_LABOUR_HOUR:(NSString *)STD_LABOUR_HOUR{
    _STD_LABOUR_HOUR = STD_LABOUR_HOUR;
    long price = [_LABOUR_PRICE doubleValue]*100;
    long quantity = [STD_LABOUR_HOUR doubleValue]*100;
    double totalPrice = price*quantity/10000.0;
    if(price != 0 && quantity != 0)
    {
        self.LABOUR_AMOUNT = [NSString stringWithFormat:@"%.2lf", totalPrice];
    }
}


- (void)setDISCOUNT:(CGFloat)DISCOUNT{
    if (self.isDiscount) {
        _DISCOUNT = DISCOUNT;
    } else {
        _DISCOUNT = 1.0;
    }
    
    long price = [self.LABOUR_AMOUNT doubleValue]*100;
    double ratioPrice = price*_DISCOUNT/100.0;
    self.DISCOUNT_AMOUNT = [NSString stringWithFormat:@"%.2lf", ratioPrice];
}

- (NSString *)REPAIR_TYPE_CODE{
    return [ICrEAMTool getRepiarTypeCodeWithRepiarName:_REPAIR_TYPE_NAME];
}

@end

@implementation ICMRepairMaintenancesModel

- (void)setupRepairMaintenancesModelWithPartsView:(ICMMaintenanceAndPartsView *)partsView{
    [partsView.repairEventArray addObjectsFromArray:partsView.delRepairEventArray];
    [partsView.delRepairEventArray removeAllObjects];
    self.TT_RECPTION_LABOUR = partsView.repairEventArray;
}

- (void)setupRepairMaintenancesModelWithArray:(NSArray *)array {
    self.TT_RECPTION_LABOUR = [array mutableCopy];

}

- (void)createRepairMaintenanceModel{
    NSMutableArray *array = [NSMutableArray array];
    for (NSDictionary *dic in self.TT_RECPTION_LABOUR) {
        ICMRepairMaintenanceModel *model = [ICMRepairMaintenanceModel yy_modelWithDictionary:dic];
        if (model.DISCOUNT == 1.0f) {
            model.IS_DISCOUNT = @"12781001";
        }
        [array addObject:model];
    }
    self.TT_RECPTION_LABOUR = array;
}

- (void)createRepairMaintenanceBookingModel{
    NSMutableArray *array = [NSMutableArray array];
    for (NSDictionary *dic in self.TT_BOOKING_ORDER_LABOUR) {
        ICMRepairMaintenanceModel *model = [ICMRepairMaintenanceModel yy_modelWithDictionary:dic];
        
        [array addObject:model];
    }
    self.TT_BOOKING_ORDER_LABOUR = array;
}

- (void)createRepairMaintenanceRoModel{
    NSMutableArray *array = [NSMutableArray array];
    for (NSDictionary *dic in self.TT_RO_LABOUR) {
        ICMRepairMaintenanceModel *model = [ICMRepairMaintenanceModel yy_modelWithDictionary:dic];
        [array addObject:model];
    }
    self.TT_RO_LABOUR = array;
}

- (void)setupRepairMaintenancesModelWithAppointmentPartsView:(ICMAppointmentMaintenanceAndPartsView *)partsView{
    [partsView.repairEventArray addObjectsFromArray:partsView.delRepairEventArray];
    [partsView.delRepairEventArray removeAllObjects];
    self.TT_BOOKING_ORDER_LABOUR = partsView.repairEventArray;
    
}

- (void)setupRepairMaintenancesModelWithRoPartsView:(ICMProxyMaintenanceAndPartsView *)partsView
{
    NSMutableArray *array = [[NSMutableArray alloc] init];
    [array addObjectsFromArray:partsView.repairEventArray];
    [array addObjectsFromArray:partsView.delRepairEventArray];
    self.TT_RO_LABOUR = array;
}

//根据view里面项目生成model 不包括删除的项目
- (void)setupRepairMaintenancesModelWithRoPartsViewWithoutDelItems:(ICMProxyMaintenanceAndPartsView *)partsView
{
    NSMutableArray *array = [[NSMutableArray alloc] init];
    [array addObjectsFromArray:partsView.repairEventArray];
    self.TT_RO_LABOUR = array;
}

@end







